package com.kingyun.gpsinspection.purificationservice.common.utils;

import org.apache.commons.lang.StringUtils;

/**
 * Created by sugongche on 2016/12/1.
 */
public class FileTypeUtil {
    public static final int TXT = 1;
    public static final int DOC = 2;
    public static final int DOCX = 3;
    public static final int XLS = 4;
    public static final int XLSX = 5;
    public static final int PPT = 6;
    public static final int PPTX = 7;
    public static final int RAR = 8;
    public static final int PDF = 9;
    public static final int ZIP = 10;

    public static final int RM = 11;
    public static final int RMVB = 12;
    public static final int WMV = 13;
    public static final int AVI = 14;
    public static final int MP4 = 15;
    public static final int MKV = 16;
    /**
     * 根据文件名称获取文件类型
     * @param fileName
     * @return
     */
    public static int getFileTypeByFileName(String fileName){
        if(StringUtils.isBlank(fileName)){
            return 0;
        }

        String suffix="";

        if(fileName.indexOf(".")>0){
            //获得文件名的后缀
            suffix=fileName.substring(fileName.indexOf(".")+1);
        }

        int fileType=0;

        if(StringUtils.isBlank(suffix)){

        }else if(suffix.equalsIgnoreCase("txt")){
            fileType=TXT;
        }else if(suffix.equalsIgnoreCase("doc")){
            fileType=DOC;
        }else if(suffix.equalsIgnoreCase("docx")){
            fileType=DOCX;
        }else if(suffix.equalsIgnoreCase("xls")){
            fileType=XLS;
        }else if(suffix.equalsIgnoreCase("xlsx")){
            fileType=XLSX;
        }else if(suffix.equalsIgnoreCase("ppt")){
            fileType=PPT;
        }else if(suffix.equalsIgnoreCase("pptx")){
            fileType=PPTX;
        }else if(suffix.equalsIgnoreCase("rar")){
            fileType=RAR;
        }else if(suffix.equalsIgnoreCase("pdf")){
            fileType=PDF;
        }else if(suffix.equalsIgnoreCase("zip")){
            fileType=ZIP;
        }else if(suffix.equalsIgnoreCase("rm")){
            fileType=RM;
        }else if(suffix.equalsIgnoreCase("rmvb")){
            fileType=RMVB;
        }else if(suffix.equalsIgnoreCase("wmv")){
            fileType=WMV;
        }else if(suffix.equalsIgnoreCase("avi")){
            fileType=AVI;
        }else if(suffix.equalsIgnoreCase("mp4")){
            fileType=MP4;
        }else if(suffix.equalsIgnoreCase("mkv")){
            fileType=MKV;
        }

        return fileType;
    }
}
